<template>
  <div class="sidebar-container">
    <div class="toggle-button" @click="toggleCollapse"><i v-if="isCollapse" class="el-icon-s-unfold"></i>
      <i  v-else class="el-icon-s-fold"></i>
    </div>
        <el-menu
          default-active="2"
          class="el-menu-vertical-demo"
          text-color="#000000"
          active-text-color="#ffd04b"
          background-color="#4a34db"
          @open="handleOpen" 
        @close="handleClose" 
        :collapse="isCollapse"
        >
          <el-submenu index="1">
            <template slot="title">
              <i class="el-icon-s-custom"></i>
              <span>Hi, Teacher</span>
            </template>
            <el-menu-item-group>
              <router-link :to="{ path: '/teacherHome' }">
                <el-menu-item index="1-1">教师主页</el-menu-item>
              </router-link>
              <router-link :to="{ path: '/updateTInfoHome' }">
                <el-menu-item index="1-2">修改我的信息</el-menu-item>
              </router-link>
            </el-menu-item-group>
          </el-submenu>
          <el-submenu index="2">
            <template slot="title">
              <i class="el-icon-menu"></i>
              <span>课程管理</span>
            </template>
            <el-menu-item-group>
              <router-link :to="{ path: '/myOfferCourse' }">
                <el-menu-item index="2-1">我开设的课程</el-menu-item>
              </router-link>
              <router-link :to="{ path: '/offerCourseList' }">
                <el-menu-item index="2-2">开设课程</el-menu-item>
              </router-link>
            </el-menu-item-group>
          </el-submenu>
          <el-submenu index="3">
            <template slot="title">
              <i class="el-icon-s-management"></i>
              <span>教师成绩管理</span>
            </template>
            <el-menu-item-group>
              <router-link :to="{ path: '/teacherGradeCourseList' }">
                <el-menu-item index="3-1">成绩管理</el-menu-item>
              </router-link>
              <router-link :to="{ path: '/teacherEditorGradeCourse' }">
                <el-menu-item index="3-2">添加学生成绩</el-menu-item>
              </router-link>
            </el-menu-item-group>
          </el-submenu>
            <el-submenu index="4">
            <template slot="title">
              <i class="el-icon-s-tools"></i>
              <span>设置</span>
            </template>
            <el-menu-item-group>
              <el-menu-item index="4-1" @click="exit">退出登录</el-menu-item>
            </el-menu-item-group>
          </el-submenu>
        </el-menu>
  </div>
</template>

<script>
export default {
  name: "TeacherNav",
  data() {
    return {
      isCollapse: true,
    };
  },
  methods: {
    exit() {
      if (confirm("是否确认退出登录，返回系统登录界面？")) {
        this.$router.push("/login");
        localStorage.clear(); 
      }
    },
    toggleCollapse() {
      this.isCollapse = !this.isCollapse
      this.$emit('childByValue', this.isCollapse)
    },
    handleOpen(key, keyPath) {
        console.log(key, keyPath);
      },
    handleClose(key, keyPath) {
        console.log(key, keyPath);
      },
  },
};
</script>

<style scoped>
.sidebar-container {
  transition: width 0.3s;
  position: relative;
  z-index: 2;
  background: #3f34db;
}

.sidebar-container.expanded {
  width: 200px;
  box-shadow: 0 0 5px rgba(0, 0, 0, 0.2);
}

.el-menu-vertical-demo:not(.el-menu--collapse) {
  width: 100%;
  height: 90%;
}
.el-menu{
     height:90%;
     border-right:0!important;
 }
 .router-link-active{
    text-decoration: none;
  }
a{
    text-decoration: none;
}
.toggle-button {
  background-color: #4a34db;
  font-size: 20px;
  line-height: 24px;
  color: #fff;
  text-align: center;
  letter-spacing: 0.2em;
  cursor: pointer;
}
</style>
